var api = require('../../utils/api.js');



Page({

    /**
     * 页面的初始数据
     */
    data: {
        lists:[],
        page:1,
        chaxun:0,
        code:''
    },

    newxurl(){
        wx.navigateTo({
          url: '/pages/chuku/add',
        })
    },
    
    getexecel(ret){
      var id=ret.currentTarget.dataset.id;
      api.post({
        url: 'excel/index',
        data: {id:id},
        success: data => {

            console.log(data.data);

            wx.downloadFile({
              url: data.data, 
              success(rs) {
                if (rs.statusCode === 200) {
                  let data = rs.tempFilePath;
                  console.log(rs);
                  wx.openDocument({
                    filePath: data,
                    showMenu: true,
                    success: function(r) {
                   
                    },
                    fail(e) {
                      console.log(e)
                    }
                  })
                } else {
                
                  console.log('报错了', rs);
                }
              }
            })

            
        }
    })


    },
    addlogs(ret){
      var id=ret.currentTarget.dataset.id;

      wx.navigateTo({
        url: '/pages/chuku/log?id='+id,
      })
    },

    printinfo(ret){

      var id=ret.currentTarget.dataset.id;

      wx.navigateTo({
        url: '/pages/chuku/add?id='+id,
      })
  },

    newxurlto(){
        wx.navigateTo({
          url: '/pages/chuku/logs',
        })
      },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
      this.setData({
        page:1,
        lists:[]
      })
      this.getmylist();
    },


     /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
      this.getmylist();
    },


    getmylist(){

      var that=this;
      var lists=this.data.lists;
      var page=this.data.page;

        this.setData({
            page:page+1
        })

        api.post({
            url: 'kuaidi/getallfile',
            data: {page:page},
            success: data => {

                var list=data.data;

                if  (list.length>0){

                  list.forEach(element => {
                    lists.push(element)
                  });
                }

                that.setData({
                    lists:lists
                })
            }
        })
    },

    closewind(){
        this.setData({
            chaxun:0
        })
    },
    selectcode(){
        this.setData({
            chaxun:1
        })
    },
    getcodetit(res){
        console.log(res);
        this.setData({
            code:res.detail.value
        })
    },
    getvode(){
        var code=this.data.code;
     
        if(code){

            this.setData({
                chaxun:0
            })
            wx.navigateTo({
                url: '/pages/chuku/select?code='+code
              })
        }
   

    }
})